﻿///////////////////////////////////////
//////add by yl 2014年8月20日14:01:31
//////主要功能:班组设备维护保养完工单
///////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Catering_DBOpertion;

namespace Catering_Model
{
    /// <summary>
    /// EMASppPlan:班组设备报修单
    /// </summary>
    [Serializable]
    public partial class EMaintenance
    {
        public EMaintenance()
        { }
        #region Model
        private int _id;
        private int _DailyManagementID;
        private string _GroupID;
        private string _ClassID;
        private string _SafeHiddenTroubleDesc;
        private bool _IsSafeEnough;
        private string _RepairingDesc;
        private DateTime? _BaoXiuDate;
        private DateTime? _StartRepairDate;
        private DateTime? _EndRepairDate;
        private string _RepairedDesc;
        private int _RepairUserState;
        private string _RepairUserZPTName;
        private string _RepairUserZPTDate;
        private string _RepairUserName;
        /// <summary>
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public int DailyManagementID
        {
            set { _DailyManagementID = value; }
            get { return _DailyManagementID; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public string GroupID
        {
            set { _GroupID = value; }
            get { return _GroupID; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public string ClassID
        {
            set { _ClassID = value; }
            get { return _ClassID; }
        }
        /// <summary>
        /// 安全隐患描述
        /// </summary>
        public string SafeHiddenTroubleDesc
        {
            set { _SafeHiddenTroubleDesc = value; }
            get { return _SafeHiddenTroubleDesc; }
        }

        /// <summary>
        /// 安全作业条件是否符合要求
        /// </summary>
        public bool IsSafeEnough
        {
            set { _IsSafeEnough = value; }
            get { return _IsSafeEnough; }
        }
        /// <summary>
        /// 维修保养过程简述
        /// </summary>
        public string RepairingDesc
        {
            set { _RepairingDesc = value; }
            get { return _RepairingDesc; }
        }
        /// <summary>
        /// 保修日期
        /// </summary>
        public DateTime? BaoXiuDate
        {
            set { _BaoXiuDate = value; }
            get { return _BaoXiuDate; }
        }
        /// <summary>
        /// 维修人员到达日期
        /// </summary>
        public DateTime? StartRepairDate
        {
            set { _StartRepairDate = value; }
            get { return _StartRepairDate; }
        }
        /// <summary>
        /// 设备维修完工日期
        /// </summary>
        public DateTime? EndRepairDate
        {
            set { _EndRepairDate = value; }
            get { return _EndRepairDate; }
        }
        /// <summary>
        /// 设备维修完工情况简述
        /// </summary>
        public string RepairedDesc
        {
            set { _RepairedDesc = value; }
            get { return _RepairedDesc; }
        }
        /// <summary>
        /// 设备维修人员工作情况（0：满意；1：基本满意；2：不满意）
        /// </summary>
        public int RepairUserState
        {
            set { _RepairUserState = value; }
            get { return _RepairUserState; }
        }
        /// <summary>
        /// 维修人员转平台名称
        /// </summary>
        public string RepairUserZPTName
        {
            set { _RepairUserZPTName = value; }
            get { return _RepairUserZPTName; }
        }
        /// <summary>
        /// 维修人员转平台日期
        /// </summary>
        public string RepairUserZPTDate
        {
            set { _RepairUserZPTDate = value; }
            get { return _RepairUserZPTDate; }
        }
        /// <summary>
        /// 维修人员姓名
        /// </summary>
        public string RepairUserName
        {
            set { _RepairUserName = value; }
            get { return _RepairUserName; }
        }
        #endregion Model
    }
}
namespace Catering_Rules
{
    /// <summary>
    /// Moon
    /// </summary>
    public partial class EMaintenance
    {
        private readonly Catering_Operation.EMaintenance dal = new Catering_Operation.EMaintenance();
        public EMaintenance()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.EMaintenance model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.EMaintenance model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.EMaintenance GetModel(int Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.EMaintenance> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.EMaintenance> DataTableToList(DataTable dt)
        {
            List<Catering_Model.EMaintenance> modelList = new List<Catering_Model.EMaintenance>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.EMaintenance model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Moon
    /// </summary>
    public partial class EMaintenance
    {
        public EMaintenance()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Moon");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.EMaintenance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into DailyRepairInfo(");
            strSql.Append("DailyManagementID,GroupID,ClassID,SafeHiddenTroubleDesc,IsSafeEnough,RepairingDesc,BaoXiuDate,StartRepairDate,EndRepairDate,RepairedDesc,RepairUserState,RepairUserZPTName,RepairUserZPTDate,RepairUserName)");
            strSql.Append(" values (");
            strSql.Append("@DailyManagementID,@GroupID,@ClassID,@SafeHiddenTroubleDesc,@IsSafeEnough,@RepairingDesc,@BaoXiuDate,@StartRepairDate,@EndRepairDate,@RepairedDesc,@RepairUserState,@RepairUserZPTName,@RepairUserZPTDate,@RepairUserName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@DailyManagementID", SqlDbType.Int,-1),
                    new SqlParameter("@GroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),
					new SqlParameter("@SafeHiddenTroubleDesc", SqlDbType.Text,-1),
					new SqlParameter("@IsSafeEnough", SqlDbType.Bit,-1),
					new SqlParameter("@RepairingDesc", SqlDbType.Text,-1),
                    new SqlParameter("@BaoXiuDate", SqlDbType.DateTime,-1),
					new SqlParameter("@StartRepairDate", SqlDbType.Date,-1),
                    new SqlParameter("@EndRepairDate", SqlDbType.Date,-1),
                    new SqlParameter("@RepairedDesc", SqlDbType.Text,-1),
                    new SqlParameter("@RepairUserState", SqlDbType.Int,-1),
					new SqlParameter("@RepairUserZPTName", SqlDbType.VarChar,50),
					new SqlParameter("@RepairUserZPTDate", SqlDbType.VarChar,50),
					new SqlParameter("@RepairUserName", SqlDbType.VarChar,50),};
            parameters[0].Value = model.DailyManagementID;
            parameters[1].Value = model.GroupID;
            parameters[2].Value = model.ClassID;
            parameters[3].Value = model.SafeHiddenTroubleDesc;
            parameters[4].Value = model.IsSafeEnough;
            parameters[5].Value = model.RepairingDesc;
            parameters[6].Value = model.BaoXiuDate;
            parameters[7].Value = model.StartRepairDate;
            parameters[8].Value = model.EndRepairDate;
            parameters[9].Value = model.RepairedDesc;
            parameters[10].Value = model.RepairUserState;
            parameters[11].Value = model.RepairUserZPTName;
            parameters[12].Value = model.RepairUserZPTDate;
            parameters[13].Value = model.RepairUserName;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.EMaintenance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DailyReportInfo set ");
            strSql.Append("EquipCName=@EquipCName,");
            strSql.Append("EquipModel=@EquipModel,");
            strSql.Append("BrandArea=@BrandArea,");
            strSql.Append("ConDesc=@ConDesc,");
            strSql.Append("UserCName=@UserCName");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@EquipCName", SqlDbType.VarChar,50),
                    new SqlParameter("@EquipModel", SqlDbType.VarChar,50),                    
                    new SqlParameter("@BrandArea", SqlDbType.VarChar,500),
                    new SqlParameter("@ConDesc", SqlDbType.Text,-1),
                    new SqlParameter("@UserCName", SqlDbType.VarChar,50),
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            //parameters[0].Value = model.EquipCName;
            //parameters[1].Value = model.EquipModel;
            //parameters[2].Value = model.BrandArea;
            //parameters[3].Value = model.ConDesc;
            //parameters[4].Value = model.UserCName;
            parameters[5].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DailyReportInfo ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Moon ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.EMaintenance GetModel(int Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,EquipCName,EquipModel,BrandArea,ConDesc,UserCName from DailyReportInfo ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            Catering_Model.EMASppPlanE model = new Catering_Model.EMASppPlanE();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.EMaintenance DataRowToModel(DataRow row)
        {
            Catering_Model.EMaintenance model = new Catering_Model.EMaintenance();
            if (row != null)
            {
                //if (row["Id"] != null && row["Id"].ToString() != "")
                //{
                //    model.Id = int.Parse(row["Id"].ToString());
                //}
                //if (row["EquipCName"] != null && row["EquipCName"].ToString() != "")
                //{
                //    model.EquipCName = row["EquipCName"].ToString();
                //}
                //if (row["EquipModel"] != null && row["EquipModel"].ToString() != "")
                //{
                //    model.EquipModel = row["EquipModel"].ToString();
                //}
                //if (row["BrandArea"] != null && row["BrandArea"].ToString() != "")
                //{
                //    model.BrandArea = row["BrandArea"].ToString();
                //}
                //if (row["ConDesc"] != null && row["ConDesc"].ToString() != "")
                //{
                //    model.ConDesc = row["ConDesc"].ToString();
                //}
                //if (row["UserCName"] != null && row["UserCName"].ToString() != "")
                //{
                //    model.UserCName = row["UserCName"].ToString();
                //}
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM DailyReportInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,MoonName,ClassId,Remark ");
            strSql.Append(" FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Moon T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Moon";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}